﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Quiz.Model
{
    public static class QuestionExtn
    {
        public static List<AnswerSet> PossibleAnswers(this Question question)
        {
            List<AnswerSet> answers = new List<AnswerSet>();
            if (!string.IsNullOrEmpty(question.AnswerDom))
            {
                StringReader reader = new StringReader(question.AnswerDom);
                XmlSerializer srz = new XmlSerializer(answers.GetType());
                var coolOb = srz.Deserialize(reader) as List<AnswerSet>;
                reader.Close();
                return coolOb;
            }
            return answers;
        }
        public static string ToAnswerString(this List<AnswerSet> answers)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);
            XmlSerializer srz = new XmlSerializer(typeof(List<AnswerSet>), new Type[] { typeof(AnswerSet) });
            srz.Serialize(writer, answers);
            writer.Close();
            return sb.ToString();
        }
    }

    [Serializable]
    public class AnswersCollection : List<AnswerSet>
    {

    }
}
